package com.sfac.javaSpringBoot.modules.account.dao;

import com.sfac.javaSpringBoot.modules.account.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PostMapping;
@Mapper
@Repository
public interface UserRepository extends JpaRepository<User,Integer>, JpaSpecificationExecutor<User> {
    User findFirstByUserNameAndEmail(String name,String password);

//    多条数据插入
    @Query(nativeQuery=true,value="insert into account(create_date,user_name,eamil,password)" +
            "values (:#{#user.createDate},:#{#user.userName},:#{#user.email},:#{#user.password})")
    @Modifying
    void insertUser(@Param("user")User user);

//    没有用到的根据id查询
//    @Query(value = "from User where id = :id")
//    User getUserById(@Param("id") int id);

//    查询所有也没有写呢
    @Query(nativeQuery = true,value ="select * from account_user u " +
            "join account_user_role r on u.id = r.user_id " +
            "join account_role on r.role_id = account_role.id where u.id = :id ")
    User getUserByIdForSql(@Param("id")int id);


}
